package org.ceteca.explica.core.management;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.partners.PartnerOT;
import org.ceteca.explica.core.warehouse.LotOT;
import org.ceteca.explica.core.warehouse.ProductOT;
import org.ceteca.explica.core.warehouse.WarehouseOT;

public class MovementOT extends BaseVO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private long idMovement;
	private ProductOT product;
	private WarehouseOT warehouse;
	private PartnerOT partner;
	private DocumentLineOT documentLine;
	private Date date=new Date();
	private BigDecimal costPrice=new BigDecimal(0.0), salesPrice=new BigDecimal(0.0);
	private BigDecimal quantity=new BigDecimal(0.0);
	private Integer version=new Integer(0);
	private Boolean incrementStock=false;
	private LotOT lot;
	
	
	
	public LotOT getLot() {
		return lot;
	}

	public void setLot(LotOT lot) {
		this.lot = lot;
	}

	public Boolean getIncrementStock() {
		return incrementStock;
	}

	public void setIncrementStock(Boolean incrementStock) {
		this.incrementStock = incrementStock;
	}

	public long getIdMovement() {
		return idMovement;
	}

	public void setIdMovement(long idMovement) {
		this.idMovement = idMovement;
	}

	public ProductOT getProduct() {
		return product;
	}

	public void setProduct(ProductOT product) {
		this.product = product;
	}

	public WarehouseOT getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(WarehouseOT warehouse) {
		this.warehouse = warehouse;
	}

	public PartnerOT getPartner() {
		return partner;
	}

	public void setPartner(PartnerOT partner) {
		this.partner = partner;
	}

	public DocumentLineOT getDocumentLine() {
		return documentLine;
	}

	public void setDocumentLine(DocumentLineOT documentLine) {
		this.documentLine = documentLine;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public BigDecimal getCostPrice() {
		return costPrice;
	}

	public void setCostPrice(BigDecimal costPrice) {
		this.costPrice = costPrice;
	}

	public BigDecimal getSalesPrice() {
		return salesPrice;
	}

	public void setSalesPrice(BigDecimal salesPrice) {
		this.salesPrice = salesPrice;
	}



	public BigDecimal	 getQuantity() {
		return quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Override
	public boolean equals(Long id) {
		return id==this.idMovement;
	}

	@Override
	public String getEntityId() {
		return InterfaceManagement.EXPLICA_ENTITY_MOVEMENT_ID;
	}

	@Override
	public long getInternalId() {

		return getIdMovement();
	}

	@Override
	public String getInternalValue() {
		if (getProduct()!=null)
			return getProduct().getDescription();
		else
			return "";
	}

	
	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getDocumentLine());
	        hcb.append(getLot());
	        hcb.append(getCostPrice());
	        hcb.append(getDate());
	        hcb.append(getIncrementStock());
	        hcb.append(getPartner());
	        hcb.append(getProduct());
	        hcb.append(getQuantity());
	        hcb.append(getSalesPrice());
	        hcb.append(getWarehouse());

	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final MovementOT other = (MovementOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getDocumentLine(), other.getDocumentLine());
	            eqb.append(getLot(), other.getLot());
	            eqb.append(getCostPrice(), other.getCostPrice());
	            eqb.append(getDate(), other.getDate());
	            eqb.append(getIncrementStock(), other.getIncrementStock());
	            eqb.append(getPartner(), other.getPartner());
	            eqb.append(getProduct(), other.getProduct());
	            eqb.append(getQuantity(), other.getQuantity());
	            eqb.append(getSalesPrice(), other.getSalesPrice());
	            eqb.append(getWarehouse(), other.getWarehouse());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }

		@Override
		public String toString() {
			StringBuilder sb= new StringBuilder();
			sb.append("------------\n");
			sb.append(this.idMovement);
			sb.append("\n");
			sb.append("------------\n");
			return sb.toString();
		}

	
}
